package net.freebytes.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LoggingHandler;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: lin
 * @time: 2024/12/3 10:26
 */
public class TestNettyServer1 {

    public static void main(String[] args) throws InterruptedException {
        Channel channel = new ServerBootstrap()
                .group(new NioEventLoopGroup())
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new LoggingHandler());
                    }
                })
                .bind(8089)
                .channel();
        System.out.println("isOpen:" + channel.isOpen() + ";;;isRegistered:" + channel.isRegistered() + ";;;isActive:" + channel.isActive());

        System.out.println("eventLoop():" + channel.eventLoop());
        System.out.println("pipeline():" + channel.pipeline());

        TimeUnit.SECONDS.sleep(5);
        System.out.println("=============================");
        System.out.println("isOpen:" + channel.isOpen() + ";;;isRegistered:" + channel.isRegistered() + ";;;isActive:" + channel.isActive());

    }

}
